package cn.tedu.sp04.order.service;

import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.sp01.service.UserService;
import cn.tedu.sp04.fegin.ItemClient;
import cn.tedu.sp04.fegin.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private ItemClient itemClient;
    @Autowired
    private UserClient userClient;


    @Override
    public Order getOrder(String orderId) {
//        TODO:远程调用用户服务，获取订单的商品列表；调用用户服务，获取用户信息
        Order order=new Order();
        order.setId(orderId);
        userClient.getUser(order.getId());
        return order;
    }

    @Override
    public void addOrder(Order order) {

        //        TODO:远程调用商品服务，减少商品内存；远程调用用户服务，增加用户积分
        itemClient.decreaseNumber(order.getItems());
        userClient.addScore(order.getUser().getId().toString(), 1000);
        log.info("订单"+order);

    }
}
